package com.kgc.xsProvider.service.ServiceImpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.kgc.basic.util.PageInfo;
import com.kgc.basic.util.ResponseMsg;
import com.kgc.xs.pojo.CustomerSummary;
import com.kgc.xs.pojo.SalesOrders;
import com.kgc.xs.pojo.TimeSummary;
import com.kgc.xs.pojo.TimeSummary1;
import com.kgc.xsProvider.dao.SalesOrderSummaryMapper;
import com.kgc.xsProvider.service.SalesOrderSummaryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SalesOrderSummaryServiceImpl implements SalesOrderSummaryService {

    private Logger logger = LoggerFactory.getLogger(SalesOrderExecutionStatusServiceImpl.class);

    @Autowired
    private SalesOrderSummaryMapper salesOrderSummaryMapper;

    @Override
    public ResponseMsg selectSummaryByCustomer(Map<String, Object> map) {
        logger.info("SalesOrderSummaryServiceImpl selectSummaryByCustomer map:{}", map);
        ResponseMsg responseMsg = new ResponseMsg();
        PageInfo<CustomerSummary> pageInfo = new PageInfo<CustomerSummary>();
        pageInfo.setPageNo(map.get("pageNo") == null ? 1 : Integer.parseInt(map.get("pageNo").toString()));
        pageInfo.setPageSize(map.get("pageSize") == null ? 10 : Integer.parseInt(map.get("pageSize").toString()));
        Page page = PageHelper.startPage(pageInfo.getPageNo(), pageInfo.getPageSize());
        List<CustomerSummary> customerSummaryList = salesOrderSummaryMapper.selectSummaryByCustomer(map);
        pageInfo.setList(customerSummaryList);
        pageInfo.setTotal((int) page.getTotal());
        responseMsg.setData(pageInfo);
        return responseMsg;
    }

    @Override
    public ResponseMsg selectSummaryByMonthTime(Map<String, Object> map) {
        logger.info("SalesOrderSummaryServiceImpl selectSummaryByMonthTime map:{}", map);
        ResponseMsg responseMsg = new ResponseMsg();
        PageInfo<TimeSummary> pageInfo = new PageInfo<>();
        pageInfo.setPageNo(map.get("pageNo") == null ? 1 : Integer.parseInt(map.get("pageNo").toString()));
        pageInfo.setPageSize(map.get("pageSize") == null ? 10 : Integer.parseInt(map.get("pageSize").toString()));
        Page page = PageHelper.startPage(pageInfo.getPageNo(), pageInfo.getPageSize());
        List<TimeSummary> timeSummaryList = salesOrderSummaryMapper.selectSummaryByMonthTime(map);
        pageInfo.setList(timeSummaryList);
        pageInfo.setTotal((int) page.getTotal());
        responseMsg.setData(pageInfo);
        return responseMsg;
    }

    @Override
    public ResponseMsg selectSummaryByYearTime(Map<String, Object> map) {
        logger.info("SalesOrderSummaryServiceImpl selectSummaryByYearTime map:{}", map);
        ResponseMsg responseMsg = new ResponseMsg();
        PageInfo<TimeSummary1> pageInfo = new PageInfo<>();
        pageInfo.setPageNo(map.get("pageNo") == null ? 1 : Integer.parseInt(map.get("pageNo").toString()));
        pageInfo.setPageSize(map.get("pageSize") == null ? 10 : Integer.parseInt(map.get("pageSize").toString()));
        Page page = PageHelper.startPage(pageInfo.getPageNo(), pageInfo.getPageSize());
        List<TimeSummary1> timeSummary1List = salesOrderSummaryMapper.selectSummaryByYearTime(map);
        pageInfo.setList(timeSummary1List);
        pageInfo.setTotal((int) page.getTotal());
        responseMsg.setData(pageInfo);
        return responseMsg;
    }

    @Override
    public ResponseMsg getTotalSalesDataByDate() {
        logger.info("SalesOrderSummaryServiceImpl getTotalSalesDataByDate is start...");
        ResponseMsg msg = new ResponseMsg();
        Map<String, Object> totalSalesDataByDate = salesOrderSummaryMapper.getTotalSalesDataByDate();
        if (totalSalesDataByDate.isEmpty()) {
            msg.setCode("301");
            msg.setMsg("未查询到相关信息");
            return msg;
        }
        msg.setCode("200");
        msg.setData(totalSalesDataByDate);
        return msg;
    }

    @Override
    public ResponseMsg getSalesOutBoundDataByTime() {
        logger.info("SalesOrderSummaryServiceImpl getSalesOutBoundDataByTime is start...");
        ResponseMsg msg = new ResponseMsg();
        Map<String, Object> salesOutBoundDataByTimeMap = salesOrderSummaryMapper.getSalesOutBoundDataByTime();
        if (salesOutBoundDataByTimeMap == null || salesOutBoundDataByTimeMap.isEmpty()) {
            msg.setCode("301");
            msg.setMsg("未查询到相关信息");
            return msg;
        }
        msg.setCode("200");
        msg.setData(salesOutBoundDataByTimeMap);
        return msg;
    }

    @Override
    public ResponseMsg getReceivableDataByTime() {
        logger.info("SalesOrderSummaryServiceImpl getReceivableDataByTime is start...");
        ResponseMsg msg = new ResponseMsg();
        Map<String, Object> receivableDataByTimeMap = salesOrderSummaryMapper.getReceivableDataByTime();
        if (receivableDataByTimeMap == null || receivableDataByTimeMap.isEmpty()) {
            msg.setCode("301");
            msg.setMsg("未查询到相关信息");
            return msg;
        }
        msg.setCode("200");
        msg.setData(receivableDataByTimeMap);
        return msg;
    }

    @Override
    public ResponseMsg getSalesReturnDataByTime() {
        logger.info("SalesOrderSummaryServiceImpl getSalesReturnDataByTime is start...");
        ResponseMsg msg = new ResponseMsg();
        Map<String, Object> salesReturnDataByTimeMap = salesOrderSummaryMapper.getSalesReturnDataByTime();
        if (salesReturnDataByTimeMap == null || salesReturnDataByTimeMap.isEmpty()) {
            msg.setCode("301");
            msg.setMsg("未查询到相关数据");
            return msg;
        }
        msg.setCode("200");
        msg.setData(salesReturnDataByTimeMap);
        return msg;
    }
}
